$(document).ready(function() {
	$(".radio").buttonset();
	$(".tabs").tabs();
	$(".corner").corner('20px');
	$(".faded").fadeTo('fast', 0.8);
	$(".box").corner('20px');
//   $('.fade').transify({
//     opacityOrig:.7
//   });
	 $(".rounded").corner();
	 $(".rounded_right").corner("right");
	 $("button").button();
	 $("input[type=submit]").button();
	 $("#inscription").buttonset();
	 $("#slider").easySlider({
	    controlsShow: true,
	    speed: 1000,
	    auto: true,
	    continuous: true, 
	    nextText: "<img src=\"/public/images/icons/next.png\"/>",
		 prevText: "<img src=\"/public/images/icons/prev.png\"/>"
	 });
	 $("input").addClass("ui-corner-all");
	 $("input").addClass("ui-widget-content");	
	$("input:text, input:password, input:file").addClass("text ui-widget-content ui-corner-all");
	$("button").button();
	$("input:submit").button();
// 	$("#tags").tagsInput({
// 		'height':'50px',
// 		'width':'300px',
// 		'unique':true,
// 		'defaultText':'Ajouter'
// 	});
// 	$('textarea.tinymce').tinymce({
// 		  script_url : '/public/javascript/tinymce/jscripts/tiny_mce/tiny_mce.js',
// 		  theme : "simple"
// 	});
		 $(".projets").fixheadertable({
		sortable: false,
		colratio: ['',75,110],
		zebra : true,
		sortType: ['string','date','string'],
		pager: true,
		rowsPerPage : 25,
		dateFormat     : 'd/m/y'
	});
	 $(".liste_projets").fixheadertable({
		sortable: false,
		colratio: ['',75,110],
		sortType: ['string','date','string'],
		rowsPerPage : 25,
		dateFormat     : 'd/m/y'
	});
	 	 $("#sendMessage").dialog({
		  autoOpen: false,
		  modal: true,
		  show: "slide",
		  hide: "slide",
		  resizable: false,
		  width: "400px",
		  buttons: {
				"Annuler": function (){
						$(this).dialog('close');
				},
				"Envoyer": function(){						
						sendMessage();
				}
		  }
	 });
	 $("#message").dialog({
		  autoOpen: false,
		  modal: true,
		  show: 'slide',
		  hide: 'slide',
		  resizable: false,
		  buttons: {
				"OK": function(){
						$(this).dialog('close');
				}
		  }
	 });
	 $("#loading").fadeTo("fast",0.5);
	 $("#loading").css("display","none");
});

function href(url){
    window.location = url;
}
function deconect(){
    $.ajax({
	type: "POST",
	url: '/mon-compte/deconnect',
	dataType: "json",
	success: function(data){
	    href("/");
	}
    });
}

function goTo(url){
	 window.location = url;
}
function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
}
function newMessage(id,name){
	 $("#to").html(name);
	 $("input[name=user_to]").val(id);
	 $("#sendMessage").dialog('open');
}
function sendMessage(){
	 if(confirm("Envoyer le message?")){
		  $.ajax({
				type: "POST",
				url: '/message/send',
				dataType: "json",
				data: {
					 user_from: $("input[name=user_from]").val(),
					 user_to: $("input[name=user_to]").val(),
					 subject: $("input[name=subject]").val(),
					 message: $("textarea[name=message]").val()
				},
				success: function(data){
					 $("#sendMessage").dialog('close');
					 $("#message").html(data.message);
					 $("#message").dialog({
						  buttons: {
								"OK": function(){
									 $(this).dialog("close");
								}
						  }
					 });
					 setTimeout("$('#message').dialog('open');",500);
				}
		  });
	 }
}
function loader(){
	 var display = $("#loading").css("display");
	 if(display == "none")
		  $("#loading").show();
	 else
		  $("#loading").hide();
}